#include <bits/stdc++.h>
using namespace std;
const int V = 20010, N = 35;
int v, n, a[N], f[V];
int main() {
  cin >> v >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = v; j >= a[i]; --j) {
      f[j] = max(f[j], f[j - a[i]] + a[i]);
    }
  }
  cout << v - f[v] << endl;
}
